@ECHO OFF

REM 创建开始菜单快捷方式

REM 设置字符编码
chcp 65001 > nul

setlocal

set appPath=%~1
set act=%~2
set type=%~3

if "%type%"=="" (
    set type=script
)

REM 检查传入文件路径是否正确

if "%appPath%"=="" ( 
    echo 应用程序路径未设置
    exit /b 1
)

if not exist "%appPath%" (
	echo %appPath% 不存在，请输入正确路径
	exit /b 2
)


SET shortcutName=%~n1
SET appName=%~nx1

set shortcutPath=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\%shortcutName%
if exist "%shortcutPath%.lnk" (	rem 快捷方式扩展名.lnk在创建时自动添加
    rem echo %shortcutPath% exist
    del "%shortcutPath%.lnk" 1>nul 2>nul
    rem echo del %shortcutPath%
)
if "%act%"=="install" (
    rem echo "mklink "%shortcutPath%" "%appPath%""
    REM mklink "%shortcutPath%" "%appPath%" 1>nul 2>nul
    call %~dp0create_shortcut.bat "%shortcutPath%" "%appPath%"
    if "%type%"=="script" (
        echo -----------    创建开始菜单快捷方式完成    ------------------------------------------------------
        pause
    )
    exit /b %errorlevel%
)
if "%act%"=="uninstall" (
    if "%type%"=="script" (
        echo -----------    移除开始菜单快捷方式完成    ------------------------------------------------------
        pause
    )
    exit /b 0
)   
exit /b 99

